package com.intretech.tj.device;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class Device {
    /**
     * mqtt名
     */
    private String mqtt;
    /**
     * 设备id
     */
    private int id;
    /**
     * 设备类型
     */
    private Type type;
    /**
     * 异常
     */
    private String error;

    /**
     * 状态
     */
    private String state;

    @JsonCreator
    public Device(@JsonProperty("id") int id, @JsonProperty("type") String type, @JsonProperty("error") String error, @JsonProperty("state") String state) {
        this.id = id;
        this.type = Type.valueOfTitle(type);
        this.error = error;
        this.state = state;
    }

    public Device(int id, Type type, String error, String state) {
        this.id = id;
        this.type = type;
        this.error = error;
        this.state = state;
    }

    /**
     * 获取设备唯一键
     *
     * @return 键名
     */
    public String getKey() {
        return type.getTitle() + id;
    }
}
